import type { FieldProps } from '../types/crud';

import { set } from '@vben/utils';

import { decorator2Prop } from '#/constant';

/**
 * @Description:实体属性装饰器
 * @Author: li shi bin
 * @Date: 10:04 2025/1/16
 * @version : V0.0.1-beta
 */

/**
 * 实体属性装饰器
 * @param prop   实体列表属性 @Link FieldProps
 * @returns 实体属性装饰器
 */
export default function Field(prop?: FieldProps | string) {
  return function (target: any, attr: any) {
    if (typeof prop === 'string') {
      prop = {
        fieldName: prop,
      };
    }
    set(target, `${decorator2Prop.entityFieldAttrs}.${attr}`, prop);
  };
}
